﻿using Industry.Framework.Common.Helper;
using Onlyle.Business;
using Onlyle.Model;
using Onlyle.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Onlyle.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        string publicPage = "~/Views/gaoxiao/_gaoxiaoPage.cshtml";
        GaoXiao_ArticleBLL articlebll = new GaoXiao_ArticleBLL();
        QingSong_ArticleBLL qingsongbll = new QingSong_ArticleBLL();
        public ActionResult Index()
        {
            AddHeadMeta("homeindex_title", "homeindex_keyword");
            return CreateGaoXiaoPage(GaoXiaoTypeEnum.gaoxiao.ToString());
        }
        public string xingzuo(string id)
        {
            Industry.Framework.Common.WebClient webClient = new Industry.Framework.Common.WebClient();
            webClient.Encoding = System.Text.Encoding.GetEncoding("utf-8");
            string result = "";
            result = (HttpRuntime.Cache.Get(id + "_xingzuo")??"").ToString();
            if (string.IsNullOrEmpty(result))
            {
                try
                {
                    result = (webClient.GetHtml("http://api.onlyle.com/api/xingzuo/get/" + id));
                    HttpRuntime.Cache.Insert(id + "_xingzuo", result, null, DateTime.Now.AddMinutes(60), TimeSpan.Zero);
                }
                catch { }
            }
            return result;
        }
        ActionResult CreateGaoXiaoPage(string type)
        {
            string pageNum = (Request.QueryString["p"] ?? "").ToString();
            List<E_GaoXiao_Article> ArticleList = articlebll.Select(pageNum, type);

            GaoXiaoListModel gaoxiaoModel = new GaoXiaoListModel();
            gaoxiaoModel.ArticleList = ArticleList;
            ViewBag.PageCount = articlebll.GetGaoXiaoArticleCountByType(type);
            ViewBag.Type = type;
            return View(publicPage, gaoxiaoModel);
        }
        void AddHeadMeta(string title, string keywords)
        {
            ViewData["title"] = ConfigHelper.GetConfigString(title);
            ViewData["keyword"] = ConfigHelper.GetConfigString(keywords);
            ViewData["description"] = ConfigHelper.GetConfigString("gaoxiao_description");
        }

    }
}
